package com.ahpu.lyf.queue;

import java.util.Arrays;

public class ArrayQueue {
    Integer front=-1;
    Integer rear=-1;
    Integer maxSize=5;
    int[] queue=new int[maxSize];

    public void addQueue(int data){
        if(front<maxSize-1){
            front++;
            queue[front]=data;
            System.out.println("数据添加成功: "+data);
            return;
        }
        System.out.println("添加失败，队列满");

    }

    public void printQueue(){
        Arrays.stream(queue).forEach(x-> System.out.print(x+" "));
    }

    public void popQueue(){
        if (rear<front){
            rear++;
            System.out.println(queue[rear]);
            return;
        }
        System.out.println("队列空");
    }

    public static void main(String[] args) {
        ArrayQueue aq=new ArrayQueue();
        aq.addQueue(1);
        aq.addQueue(2);
        aq.addQueue(3);
        aq.addQueue(4);
        aq.addQueue(5);
        aq.addQueue(6);
        aq.popQueue();
        aq.popQueue();
        aq.popQueue();
        aq.popQueue();
        aq.popQueue();
        aq.popQueue();
        aq.printQueue();
    }
}

